package com.dao;

import java.util.Map;

import com.alibaba.fastjson2.JSON;
import com.servlet.My;

import hyl.core.db.MyDB;
import hyl.core.db.MySqlSelect;
import hyl.core.db.MySqlSelect2;
import hyl.core.db.SelectWhere;
import hyl.core.info.Content;

public class SqlOfTrade {
	// xml 2019-03-06 获取商品列表
	public static Map<String, Object> get获取商品明细(int index, int size, int type, String 名称, int 状态) {
		Content ct = new Content();
		MySqlSelect count = MySqlSelect
				.getInstance("select count(1) as total from km_project a,km_project_ext b where a.id=b.id");
		String sql = "select a.id,a.state,a.name,a.t0,a.content,a.types,a.remark,b.l0,a.pid,a.t1,b.l1 from km_project a,km_project_ext b where a.id=b.id {1} order by a.id desc {2} ";

		MySqlSelect2 select = MySqlSelect2.getInstance(sql);
		SelectWhere sw = new SelectWhere();
		sw.add(" and a.pid=?", type);
		sw.addLike(" and a.name like ?", 名称);
		if (状态 != -1) {
			sw.add(" and a.state=?", 状态);
		}
		count.addParams(sw);
		select.addParams(1, sw);
		select.fromto(2, index, size);

		ct.setCode(1, "查询成功");
		ct.iniBodys(count.getMap());
		ct.addBodyItem("_rs", select.getList2D());
		return ct.get();
	}

	// xml 添加商品name,styles,prices,types,remark,text,state
	public static void add商品(String name, String styles, String prices, String level, String remark, String text,
			String state, String leixing, String 积分) {
		MyDB db = My.getCommitDB1();
		String sql = "insert into km_project(state,name,t0,content,t1,remark,pid)values(?,?,?,?,?,?,?)";
		Object[] param = { state, name, styles, text, level, remark, leixing };
		Long id = db.executeUpdate(sql, param);
		sql = "insert into km_project_ext(id,l0,l1)values(?,?,?)";
		Object[] param1 = { id, prices, 积分 };
		db.executeUpdate(sql, param1);
		db.commit();
	}

	// xml 获取单件商品信息
	public static String get商品信息(String id) {
		MyDB db = My.getDB1();
		String sql = "select a.id,a.state,a.name,a.t0,a.content,a.t1,a.remark,a.pid,b.l0,b.l1 from km_project a,km_project_ext b where a.id=b.id and a.id=? ";
		Object[] param = { id };
		return JSON.toJSONString(db.queryMap(sql, param));
	}

	// xml 修改商品信息
	public static void change商品(String id, String name, String styles, String prices, String level, String remark,
			String text, String state, String leixing, String 积分) {
		MyDB db = My.getCommitDB1();
		String sql = "update km_project set state=?,name=?,t0=?,content=?,t1=?,remark=?,pid=? where id=?";
		Object[] param = { state, name, styles, text, level, remark, leixing, id };
		db.executeUpdate(sql, param);
		String sql2 = "update km_project_ext set l0=?,l1=? where id=?";
		Object[] param1 = { prices, 积分, id };
		db.executeUpdate(sql2, param1);
		db.commit();
	}

	// 管理员获取所有订单信息
	public static Map<String, Object> get订单(int index, int size) {
		Content ct = new Content();
		MySqlSelect count = MySqlSelect.getInstance("select count(1) as total from book_project where remark='重消商品'");
		String sql = "select b.uname,a.name,a.t0,a.content,d.l0,c.track,c.flowid from km_project a,user b,flow c,book_project d where d.buser=b.id and d.fid=c.flowid and d.t0=a.id and d.remark='重消商品' {1}  ";
		MySqlSelect2 select = MySqlSelect2.getInstance(sql);
		select.fromto(1, index, size);
		ct.setCode(1, "查询成功");
		ct.iniBodys(count.getMap());
		ct.addBodyItem("_rs", select.getList2D());
		return ct.get();
	}
}
